/**
 * Created by JetBrains WebStorm.
 * User: Silence
 * Date: 3/21/12
 * Time: 8:38 AM
 * To change this template use File | Settings | File Templates.
 */

Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath('Ext.ux', 'extjs/examples/ux/');

Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.tip.QuickTipManager',
    'Ext.ux.LiveSearchGridPanel'
]);

var rowEditing = Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 2
});

var sm = Ext.create('Ext.selection.CheckboxModel', {
    listeners: {
        selectionchange: function(sm, selections) {
            for (var i = 0; i < selections.length; i++) {
                var record = selections[i];
            }
            Ext.getCmp('removebutton').setDisabled(selections.length == 0);
            Ext.getCmp('sendemailbutton').setDisabled(selections.length == 0);
        }
    }
});

Ext.define('EM.view.event.AllPeopleView', {
    extend: 'Ext.ux.LiveSearchGridPanel',
    id: 'allpeopleview',
    alias: 'widget.allpeopleview',
    store: 'PersonStore',
    columnLines: true,
    selModel: sm,
    columns: [
        { text: 'First Name', flex: 1, sortable: true, dataIndex: 'firstname', editor: {xtype: 'textfield', allowBlank: false}},
        { text: 'Last Name', flex: 1, sortable: true, dataIndex: 'lastname', editor: 'textfield'},
        { text: 'Description', flex: 1, sortable: true, dataIndex: 'description', editor: 'textfield'},
        { text: 'Email', flex: 1, sortable: true, dataIndex: 'email', editor: {xtype: 'textfield', allowBlank: false}},
        { text: 'Contact No.', flex: 1, sortable: true, dataIndex: 'contact_no', editor: 'textfield'}
    ],
    plugins: [ rowEditing ],
    viewConfig: {
        stripeRows: true
    },
    features: [{ ftype: 'grouping' }],
    dockedItems: [
        {
            xtype: 'toolbar',
            dock: 'top',
            items: [
                {
                    xtype: 'exporterbutton',
                    id: 'downloadallbutton',
                    text: 'Excel',
                    swfPath: './extjs/examples/ux/exporter/downloadify.swf',
                    downloadImage: './extjs/examples/ux/exporter/download.png'
                }
            ]
        }
    ],
    updateActiveEvent: function(button) {
        this.eventId = button.getId();
        this.updateStore();
    },
    updateStore: function() {
        var filter = Ext.getCmp('eventpeople').text;
        if (filter == 'All') {
            this.store.clearFilter(true);

            this.setTitle(filter + ' List');
            this.store.filter('event', this.eventId);
            this.store.group('category');
        }
    }
});